package com.example.hanchen.yongkanggy.home.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hanchen.yongkanggy.R;
import com.example.hanchen.yongkanggy.home.activity.EarlyWarningDetailsActivity;
import com.example.hanchen.yongkanggy.home.activity.InspectionDetailsActivity;
import com.example.hanchen.yongkanggy.home.adapter.ControlitemAdapter;
import com.example.hanchen.yongkanggy.home.adapter.WarnlitemAdapter;
import com.example.hanchen.yongkanggy.home.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class WarnitemFragment extends BaseFragment {
    TextView tv_name;
    int mParam;

    RecyclerView rv_list;
    WarnlitemAdapter warnlitemAdapter;

    List<String> stringList = new ArrayList<>();
    TextView tv_full,tv_unwound,tv_discharged;

    public static WarnitemFragment newInstance(int mParam) {//int typePosition
        Bundle args = new Bundle();
        WarnitemFragment fragment = new WarnitemFragment();
        args.putInt("mParam", mParam);
        fragment.setArguments(args);
        return fragment;
    }

    @SuppressLint("MissingInflatedId")
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_warnitem, container, false);
        rv_list = view.findViewById(R.id.rv_list);
        tv_full = view.findViewById(R.id.tv_full);
        tv_unwound = view.findViewById(R.id.tv_unwound);
        tv_discharged = view.findViewById(R.id.tv_discharged);


        if (getArguments() != null) {
            mParam = getArguments().getInt("mParam");
            if (mParam == 0) {
                for (int i = 0; i < 5; i++) {
                    stringList.add("");
                }
            } else if (mParam == 1) {
                for (int i = 0; i < 3; i++) {
                    stringList.add("");
                }
            } else if (mParam == 2) {
                for (int i = 0; i < 1; i++) {
                    stringList.add("");
                }
            }
        }

        warnlitemAdapter = new WarnlitemAdapter(getActivity(), new WarnlitemAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                startActivity(new android.content.Intent(getActivity(), EarlyWarningDetailsActivity.class));
            }
        });
        rv_list.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_list.setAdapter(warnlitemAdapter);
        warnlitemAdapter.setTabData(stringList);


        tv_full.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_full.setBackgroundResource(R.drawable.bg_while_sxzy);
                tv_full.setTextColor(getResources().getColor(R.color.color_000000));

                tv_unwound.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_unwound.setTextColor(getResources().getColor(R.color.white));

                tv_discharged.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_discharged.setTextColor(getResources().getColor(R.color.white));
//                viewPager.setCurrentItem(0);

            }
        });

        tv_unwound.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_unwound.setBackgroundResource(R.drawable.bg_while_sxzy);
                tv_unwound.setTextColor(getResources().getColor(R.color.color_000000));

                tv_full.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_full.setTextColor(getResources().getColor(R.color.white));

                tv_discharged.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_discharged.setTextColor(getResources().getColor(R.color.white));
//                viewPager.setCurrentItem(1);
            }
        });

        tv_discharged.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_discharged.setBackgroundResource(R.drawable.bg_while_sxzy);
                tv_discharged.setTextColor(getResources().getColor(R.color.color_000000));

                tv_full.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_full.setTextColor(getResources().getColor(R.color.white));

                tv_unwound.setBackgroundResource(R.drawable.bg_blue_sxzy);
                tv_unwound.setTextColor(getResources().getColor(R.color.white));
//                viewPager.setCurrentItem(2);
            }
        });


        return view;
    }




}
